<?php

include('loader.php');

$tpl = new Proto_Template("example.html");
$html = $tpl->getHtml();

$posts = include('example.php');

foreach ($html->select('ul#post-list')->loop($posts) as $item) {
	list($li, $post) = $item;
	$li->p = $post['body'];
	$li->h2 = $post['title'];
	$li->span->em = sprintf($li->span->em, $post['date']);
	$li->span->em->a['href'] = "mailto:".$post['author']['email'];
	$li->span->em->a = $post['author']['name'];

	if(empty($post['comments'])) {
		unset($li->ul);
		unset($li->h3);
	} else {
		foreach ($li->ul->loop($post['comments']) as $item) {
			list($li, $post) = $item;
			$li->h4 = $post['title'];
			$li->p = $post['body'];
			$li->span->em->evaluate($post); //this is same as
			//$li->span->em = str_replace(array_keys($post), array_values($post), $li->span->em);
		}
	}


}

echo $html->render();
?>